package com.bifrost.admin.controller;


import com.bifrost.model.ResultModel;
import com.bifrost.model.vo.PageVO;
import com.bifrost.service.AdminOrderTransactionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * create by wqhe
 */
@Api("后台订单交易相关接口")
@RequestMapping("/admin/orderTransaction")
@RestController
public class AdminOrderTransactionController {

    @Autowired
    AdminOrderTransactionService adminOrderTransactionService;

    @GetMapping("/page")
    @ApiOperation("分页查询订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderNumber" , value = "查询条件(订单号)",dataType = "String" ,paramType = "query"),
            @ApiImplicitParam(name = "startTime" , value = "查询条件(订单创建时间的左区间)",dataType = "String" ,paramType = "query"),
            @ApiImplicitParam(name = "endTime" , value = "查询条件(订单创建时间的右区间)",dataType = "String" ,paramType = "query"),
            @ApiImplicitParam(name = "pageCode" , value = "当前页(默认为第一页)" , dataType = "int" , paramType = "query"),
            @ApiImplicitParam(name = "pageSize" , value = "单页显示条数(默认为10个)" ,  dataType = "int" , paramType = "query")
    })
    public ResultModel listOrderTransaction(String orderNumber, String startTime, String endTime, @RequestParam(defaultValue = "1") Integer pageCode, @RequestParam(defaultValue = "10") Integer pageSize){
        PageVO pageVO = adminOrderTransactionService.list(orderNumber,startTime,endTime,pageCode,pageSize);
        if(pageVO != null && !CollectionUtils.isEmpty(pageVO.getRecordList())){
            return ResultModel.ok().put("pageVO",pageVO);
        }
        return ResultModel.error("没有数据");
    }
}
